package com.settlement.system.controller;

import com.settlement.system.common.annotation.Swagger;
import com.settlement.system.common.enums.ReturnStatusEnum;
import com.settlement.system.common.annotation.LoggerProfile;
import com.settlement.system.model.param.*;
import com.settlement.system.reply.ObjectDataResponse;
import com.settlement.system.common.util.common.JwtUtil;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 唯品会账单明细 前端控制器
 * @author Ximi
 * @since 2020-04-15
 */
@Swagger
@Slf4j
@RestController
@RequestMapping("/token")
public class TokenController {

    @ApiOperation(value = "获取token")
    @LoggerProfile(methodNote="获取token")
    @RequestMapping(value = "/getToken", method = RequestMethod.POST)
    public ObjectDataResponse<TblRpaTokenApiResponseParams> getAvailableBankCard(@RequestBody TblRpaTokenApiRequestParams model) {
        try {
            String message = model.verify(model);
            if (!StringUtils.isEmpty(message)) {
                return new ObjectDataResponse(ReturnStatusEnum.CHECK_FAILURE.getValue(), message);
            }
            TblRpaTokenApiResponseParams result = JwtUtil.neverExpireLogin(model);
            String errorMsg = result.getErrorMsg();
            if(StringUtils.isNotEmpty(errorMsg)){
                return new ObjectDataResponse(ReturnStatusEnum.CHECK_FAILURE.getValue(), errorMsg);
            }
            return new ObjectDataResponse<>(result, 200, "success");
        } catch (Exception ex) {
            log.error("获取token出错", ex);
            return new ObjectDataResponse(500, "服务器异常");
        }
    }


}

